#include <codecvt>

#include "../MessageEncoding.h"

static_assert(sizeof(char) == 1, "char is a byte");

std::vector<char> snake::StringToBytes(const std::string &string)
{
  return std::vector<char>(string.cbegin(), string.cend());
}

std::vector<char> snake::StringToBytes(const std::wstring &wstring)
{
  std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
  std::string string = converter.to_bytes(wstring);
  std::vector<char> bytes(string.cbegin(), string.cend());
  return bytes;
}

std::wstring snake::StringFromBytes(const std::vector<char> &bytes)
{
  std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
  return converter.from_bytes(std::string(bytes.cbegin(), bytes.cend())); // may be optimized
}
